from pip._internal.utils import logging
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import time
from selenium.webdriver.common.action_chains import ActionChains
# 配置ChromeOptions，设置detach为True，使浏览器窗口不会自动关闭
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("detach", True)

# 指定chromedriver的实际路径
chromedriver_path = r'C:\Program Files\Google\Chrome\Application\chromedriver.exe'
service = Service(executable_path=chromedriver_path)

# 创建Chrome浏览器实例
driver = webdriver.Chrome(options=chrome_options, service=service)


# 打开懂车帝销售页面
driver.get("https://www.dongchedi.com/sales")

button = driver.find_element(By.CSS_SELECTOR, ".tw-relative.more_item__2UARp")
actions = ActionChains(driver)
actions.move_to_element(button)
actions.perform()  # 执行构建好的鼠标动作链，实现鼠标悬停效果
button2 = driver.find_elements(By.CSS_SELECTOR, "a.more_option___6xpL")
for b in button2:
    element_text = b.text  # 获取元素的文本内容
    if element_text == "2024年10月":
        b.click()  # 如果文本内容符合要求，点击该按钮

